package p270jp.pxv.android.activity;

import android.content.ComponentCallbacks;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ImageView;
import androidx.databinding.DataBindingUtil;
import androidx.databinding.ViewDataBinding;
import androidx.fragment.app.BackStackRecord;
import java.util.Arrays;
import java.util.Locale;
import p014ae.AbstractActivityC0056c2;
import p014ae.View$OnClickListenerC0143q5;
import p014ae.View$OnClickListenerC0148r5;
import p047bg.C1124a;
import p062c4.ViewBindings;
import p064c6.Preconditions;
import p134ei.AnalyticsAction;
import p134ei.AnalyticsScreenName;
import p187gl.PixivRequest;
import p189gn.AbstractC3435a;
import p189gn.AbstractC3446l;
import p210hh.PixivAccountManager;
import p216hn.DefaultConstructorMarker;
import p216hn.Lambda;
import p216hn.Reflection;
import p270jp.pxv.android.R;
import p270jp.pxv.android.legacy.model.PixivUser;
import p270jp.pxv.android.model.PixivNovelSeriesDetail;
import p270jp.pxv.android.response.PixivResponse;
import p307l9.EdgeTreatment;
import p314lg.ActivityNovelSeriesDetailBinding;
import p325m0.MutabilityOwnership;
import p436q6.StringMerger;
import p467rd.subscribers;
import p547uh.NovelSeriesDetailFragment;
import p579vo.Qualifier;
import p603wm.AbstractC6949c;
import p603wm.Unit;
import p645yc.AndroidSchedulers;
import p671zc.CompositeDisposable;
import p677zi.PixivImageLoader;

/* compiled from: NovelSeriesDetailActivity.kt */
/* renamed from: jp.pxv.android.activity.NovelSeriesDetailActivity */
/* loaded from: classes2.dex */
public final class NovelSeriesDetailActivity extends AbstractActivityC0056c2 {

    /* renamed from: g0 */
    public static final C4031a f18438g0 = new C4031a(null);

    /* renamed from: b0 */
    public ActivityNovelSeriesDetailBinding f18439b0;

    /* renamed from: c0 */
    public PixivNovelSeriesDetail f18440c0;

    /* renamed from: d0 */
    public long f18441d0;

    /* renamed from: e0 */
    public final CompositeDisposable f18442e0 = new CompositeDisposable();

    /* renamed from: f0 */
    public final AbstractC6949c f18443f0 = Preconditions.m9802P(1, new C4034d(this, null, null));

    /* compiled from: NovelSeriesDetailActivity.kt */
    /* renamed from: jp.pxv.android.activity.NovelSeriesDetailActivity$a */
    /* loaded from: classes2.dex */
    public static final class C4031a {
        public C4031a(DefaultConstructorMarker eVar) {
        }

        /* renamed from: a */
        public final Intent m4800a(Context context, long j, long j2) {
            MutabilityOwnership.m3745m(context, "context");
            EdgeTreatment.m3910h(j > 0);
            Intent intent = new Intent(context, NovelSeriesDetailActivity.class);
            intent.putExtra("NOVEL_SERIES_ID", j);
            intent.putExtra("NOVEL_SERIES_USER_ID", j2);
            return intent;
        }
    }

    /* compiled from: NovelSeriesDetailActivity.kt */
    /* renamed from: jp.pxv.android.activity.NovelSeriesDetailActivity$b */
    /* loaded from: classes2.dex */
    public static final class C4032b extends Lambda implements AbstractC3446l<Throwable, Unit> {

        /* renamed from: b */
        public final /* synthetic */ long f18445b;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        public C4032b(long j) {
            super(1);
            NovelSeriesDetailActivity.this = r1;
            this.f18445b = j;
        }

        @Override // p189gn.AbstractC3446l
        public Unit invoke(Throwable th) {
            Throwable th2 = th;
            MutabilityOwnership.m3745m(th2, "throwable");
            ActivityNovelSeriesDetailBinding n0Var = NovelSeriesDetailActivity.this.f18439b0;
            if (n0Var != null) {
                n0Var.f21978t.m4597b(StringMerger.m2850l(th2), new View$OnClickListenerC0143q5(NovelSeriesDetailActivity.this, this.f18445b));
                return Unit.f29503a;
            }
            MutabilityOwnership.m3737u("binding");
            throw null;
        }
    }

    /* compiled from: NovelSeriesDetailActivity.kt */
    /* renamed from: jp.pxv.android.activity.NovelSeriesDetailActivity$c */
    /* loaded from: classes2.dex */
    public static final class C4033c extends Lambda implements AbstractC3446l<PixivResponse, Unit> {

        /* renamed from: b */
        public final /* synthetic */ long f18447b;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        public C4033c(long j) {
            super(1);
            NovelSeriesDetailActivity.this = r1;
            this.f18447b = j;
        }

        @Override // p189gn.AbstractC3446l
        public Unit invoke(PixivResponse pixivResponse) {
            PixivResponse pixivResponse2 = pixivResponse;
            if (!TextUtils.isEmpty(pixivResponse2.profile.backgroundImageUrl)) {
                PixivImageLoader e1 = NovelSeriesDetailActivity.m4802e1(NovelSeriesDetailActivity.this);
                NovelSeriesDetailActivity novelSeriesDetailActivity = NovelSeriesDetailActivity.this;
                String str = pixivResponse2.profile.backgroundImageUrl;
                MutabilityOwnership.m3746l(str, "response.profile.backgroundImageUrl");
                ActivityNovelSeriesDetailBinding n0Var = NovelSeriesDetailActivity.this.f18439b0;
                if (n0Var != null) {
                    ImageView imageView = n0Var.f21984z;
                    MutabilityOwnership.m3746l(imageView, "binding.userBackgroundImageView");
                    e1.m62d(novelSeriesDetailActivity, str, imageView);
                } else {
                    MutabilityOwnership.m3737u("binding");
                    throw null;
                }
            } else {
                PixivImageLoader e12 = NovelSeriesDetailActivity.m4802e1(NovelSeriesDetailActivity.this);
                NovelSeriesDetailActivity novelSeriesDetailActivity2 = NovelSeriesDetailActivity.this;
                String medium = pixivResponse2.user.profileImageUrls.getMedium();
                ActivityNovelSeriesDetailBinding n0Var2 = NovelSeriesDetailActivity.this.f18439b0;
                if (n0Var2 != null) {
                    ImageView imageView2 = n0Var2.f21984z;
                    MutabilityOwnership.m3746l(imageView2, "binding.userBackgroundImageView");
                    e12.m62d(novelSeriesDetailActivity2, medium, imageView2);
                } else {
                    MutabilityOwnership.m3737u("binding");
                    throw null;
                }
            }
            PixivImageLoader e13 = NovelSeriesDetailActivity.m4802e1(NovelSeriesDetailActivity.this);
            NovelSeriesDetailActivity novelSeriesDetailActivity3 = NovelSeriesDetailActivity.this;
            String medium2 = pixivResponse2.user.profileImageUrls.getMedium();
            ActivityNovelSeriesDetailBinding n0Var3 = NovelSeriesDetailActivity.this.f18439b0;
            if (n0Var3 != null) {
                ImageView imageView3 = n0Var3.f21981w;
                MutabilityOwnership.m3746l(imageView3, "binding.toolBarUserIconImageView");
                e13.m60f(novelSeriesDetailActivity3, medium2, imageView3);
                ActivityNovelSeriesDetailBinding n0Var4 = NovelSeriesDetailActivity.this.f18439b0;
                if (n0Var4 != null) {
                    n0Var4.f21983y.setText(pixivResponse2.user.name);
                    NovelSeriesDetailActivity novelSeriesDetailActivity4 = NovelSeriesDetailActivity.this;
                    ActivityNovelSeriesDetailBinding n0Var5 = novelSeriesDetailActivity4.f18439b0;
                    if (n0Var5 != null) {
                        n0Var5.f21982x.setOnClickListener(new View$OnClickListenerC0148r5(novelSeriesDetailActivity4, this.f18447b));
                        PixivUser pixivUser = pixivResponse2.user;
                        ActivityNovelSeriesDetailBinding n0Var6 = NovelSeriesDetailActivity.this.f18439b0;
                        if (n0Var6 != null) {
                            n0Var6.f21980v.m4495a(pixivUser, AnalyticsAction.FOLLOW_VIA_PROFILE, AnalyticsAction.UNFOLLOW_VIA_PROFILE);
                            if (pixivUser.f19078id != PixivAccountManager.m5511e().f16499e) {
                                ActivityNovelSeriesDetailBinding n0Var7 = NovelSeriesDetailActivity.this.f18439b0;
                                if (n0Var7 != null) {
                                    n0Var7.f21980v.setVisibility(0);
                                } else {
                                    MutabilityOwnership.m3737u("binding");
                                    throw null;
                                }
                            }
                            return Unit.f29503a;
                        }
                        MutabilityOwnership.m3737u("binding");
                        throw null;
                    }
                    MutabilityOwnership.m3737u("binding");
                    throw null;
                }
                MutabilityOwnership.m3737u("binding");
                throw null;
            }
            MutabilityOwnership.m3737u("binding");
            throw null;
        }
    }

    /* compiled from: ComponentCallbackExt.kt */
    /* renamed from: jp.pxv.android.activity.NovelSeriesDetailActivity$d */
    /* loaded from: classes2.dex */
    public static final class C4034d extends Lambda implements AbstractC3435a<PixivImageLoader> {

        /* renamed from: a */
        public final /* synthetic */ ComponentCallbacks f18448a;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        public C4034d(ComponentCallbacks componentCallbacks, Qualifier aVar, AbstractC3435a aVar2) {
            super(0);
            this.f18448a = componentCallbacks;
        }

        /* JADX WARN: Type inference failed for: r0v4, types: [java.lang.Object, zi.a] */
        @Override // p189gn.AbstractC3435a
        public final PixivImageLoader invoke() {
            return C1124a.m10173s(this.f18448a).f24118a.m920a().m621a(Reflection.m5499a(PixivImageLoader.class), null, null);
        }
    }

    /* renamed from: e1 */
    public static final PixivImageLoader m4802e1(NovelSeriesDetailActivity novelSeriesDetailActivity) {
        return (PixivImageLoader) novelSeriesDetailActivity.f18443f0.getValue();
    }

    /* renamed from: f1 */
    public final void m4801f1(long j) {
        ViewBindings.m9836a(subscribers.m2589g(PixivRequest.m5805l(j).m986o(AndroidSchedulers.m334a()), new C4032b(j), null, new C4033c(j), 2), this.f18442e0);
    }

    @Override // p270jp.pxv.android.activity.AbstractActivityC4151b, p270jp.pxv.android.activity.BaseActivity, androidx.fragment.app.FragmentActivity, androidx.activity.ComponentActivity, p248j2.ActivityC3902g, android.app.Activity
    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        ViewDataBinding d = DataBindingUtil.m11369d(this, R.layout.activity_novel_series_detail);
        MutabilityOwnership.m3746l(d, "setContentView(this, R.l…vity_novel_series_detail)");
        ActivityNovelSeriesDetailBinding n0Var = (ActivityNovelSeriesDetailBinding) d;
        this.f18439b0 = n0Var;
        C1124a.m10196R(this, n0Var.f21979u, "");
        long longExtra = getIntent().getLongExtra("NOVEL_SERIES_ID", -1);
        long longExtra2 = getIntent().getLongExtra("NOVEL_SERIES_USER_ID", -1);
        this.f18441d0 = longExtra2;
        if (longExtra2 > 0) {
            m4801f1(longExtra2);
        }
        this.f18757A.m6524f(AnalyticsScreenName.NOVEL_SERIES_DETAIL, Long.valueOf(longExtra));
        BackStackRecord cVar = new BackStackRecord(m11131K0());
        NovelSeriesDetailFragment t6Var = new NovelSeriesDetailFragment();
        Bundle bundle2 = new Bundle();
        bundle2.putLong("NOVEL_SERIES_ID", longExtra);
        t6Var.setArguments(bundle2);
        cVar.m11165j(R.id.fragment_container, t6Var);
        cVar.mo11171d();
    }

    @Override // androidx.activity.ComponentActivity, android.app.Activity
    public boolean onCreateOptionsMenu(Menu menu) {
        MutabilityOwnership.m3745m(menu, "menu");
        getMenuInflater().inflate(R.menu.menu_novel_series_detail, menu);
        return true;
    }

    @Override // p014ae.AdActivity, p270jp.pxv.android.activity.BaseActivity, p116e.ActivityC2727f, androidx.fragment.app.FragmentActivity, android.app.Activity
    public void onDestroy() {
        this.f18442e0.m80f();
        super.onDestroy();
    }

    @Override // p270jp.pxv.android.activity.AbstractActivityC4151b, androidx.activity.ComponentActivity, android.app.Activity
    public boolean onOptionsItemSelected(MenuItem menuItem) {
        MutabilityOwnership.m3745m(menuItem, "item");
        if (menuItem.getItemId() != R.id.menu_share) {
            return super.onOptionsItemSelected(menuItem);
        }
        PixivNovelSeriesDetail pixivNovelSeriesDetail = this.f18440c0;
        if (pixivNovelSeriesDetail != null) {
            String format = String.format(Locale.US, "%s | %s #pixiv https://www.pixiv.net/novel/series/%d", Arrays.copyOf(new Object[]{pixivNovelSeriesDetail.title, pixivNovelSeriesDetail.user.name, Long.valueOf(pixivNovelSeriesDetail.f19133id)}, 3));
            MutabilityOwnership.m3746l(format, "java.lang.String.format(locale, format, *args)");
            Intent intent = new Intent("android.intent.action.SEND");
            intent.setType("text/plain");
            intent.putExtra("android.intent.extra.TEXT", format);
            startActivity(Intent.createChooser(intent, null));
        }
        return true;
    }
}
